login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > PHP > GD library > [GD]txt > png

[GD]txt > png

Auteur: kiwi - 03 maart 2010 - 14:06 - Gekeurd door: Stijn - Hits: 4857 - Aantal punten: 4.00 (3 stemmen)




Het is een simpel scriptje om tekst om te zetten naar een transparante PNG,

het gemakkelijke is als je de link veranderd veranderd de img ook ;D
als je het op een site/forum gewoon tussen de [img] ... [/img] krijg je de afbeelding te zien

je hebt meerdere lettertypen beschikbaar*
je kan de kleur instellen custum en een paar defaults
de breede van de img kan je instellen en is nodig als je voor een lange tekst gaat
de groote word automatisch aangepast naargelang de groote van het lettertype

uitgerust met een error systeem, maar aangezien alleen er een error was voor als je geen tekst invuld (test maar ;D)

* somige tekens werken niet bij alle lettertypes
---------------------------------------------
-[instalatie]-
ALGEMEEN
gewoon de files naar de folder naar keuze.

FONTS:
plaats de fonts (aleen *.tff) in de map "fonts"
dan in de enter_field.php zoek je naar:
  1. <td>Font :</td>
  2. <td><select name="font">
  3. <option value="MASTERPLAN">Masterplan</option>
  4. <option value="SNIPER">Sniper</option>
  5. <option value="Saint-Andrews Queen">Saint-Andrews Queen</option>
  6. <option value="Harabara">Harabara</option>
  7. <option value="Action_of_The_Time_A_L">Action of the time</option>
  8. <option value="bankgothic-regular-db">BankGothic</option>
  9. <option value="evanescent">Evanescent</option>
  10. <option value="Beyond_Wonderland">Beyond wonderland</option>
  11. </select>
  12. </td>

en daar voeg je ze toe, en bij value vul je de naam in zonder .tff en daarachter hetgeen moet getoond worden in de form

Code:
index.php

  1. <?php
  2. if (isset ($_GET['txt']))
  3. {
  4. header("Content-type: image/png"); //Picture Format
  5. header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); //Consitnuously modified
  6. header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
  7. header("Pragma: no-cache"); // NO CACHE
  8.  
  9. if (empty ($_GET['size']))
  10. {
  11. $h = 85;
  12. } else {
  13. $h = $_GET['size'] + 25;
  14. }
  15. if (empty ($_GET['width']))
  16. {
  17. $w = 500;
  18. } else {
  19. $w = $_GET['width'];
  20. }
  21. $bg = imagecreatetruecolor($w, $h);
  22.  
  23. //This will make it transparent
  24. imagesavealpha($bg, true);
  25. $trans_colour = imagecolorallocatealpha($bg, 255, 0, 0, 127);
  26. imagefill($bg, 0, 0, $trans_colour);
  27.  
  28. //Text to be written
  29. if (empty ($_GET['txt']))
  30. {
  31. header ("refresh: 0; index.php?e=t");
  32. } else {
  33. $Text = $_GET['txt'];
  34. $Text = stripslashes($Text);
  35. $Text = strip_tags($Text);
  36. $Text = htmlspecialchars ($Text);
  37. }
  38. //Color select
  39. //Default colors
  40. if ( $_GET['color'] != 'custom')
  41. {
  42. $black = imagecolorallocate($bg, 0,0,0);
  43. $white = imagecolorallocate($bg, 255, 255, 255);
  44. $red = imagecolorallocate($bg, 255,0,0);
  45. $grey = imagecolorallocate($bg, 128, 128, 128);
  46. $green = imagecolorallocate($bg, 0,255,0);
  47. $yellow = imagecolorallocate($bg, 255,255,0);
  48. $blue = imagecolorallocate($bg, 0,0,255);
  49. $color = $$_GET['color'];
  50. } else {
  51. if (empty($_GET['red'])) { $red = 0;} else { $red = $_GET['red']; }
  52. if (empty($_GET['green'])) { $green = 0;} else { $green = $_GET['green']; }
  53. if (empty($_GET['blue'])) { $blue = 0;} else { $red = $_GET['blue']; }
  54.  
  55. $color = imagecolorallocate($bg, $red, $green, $blue);
  56. }
  57.  
  58. //Select font
  59. $font = 'fonts/'.$_GET['font'].'.ttf';
  60.  
  61. //Font size
  62. if (empty ($_GET['size']))
  63. {
  64. $fontsize = 60;
  65. } else {
  66. $fontsize = $_GET['size'];
  67. }
  68. $Xpos = $fontsize + 10;
  69. $Ypos = 15;
  70. $Rot = 0;
  71. imagettftext($bg, $fontsize, $Rot, $Ypos, $Xpos, $color, $font, $Text);
  72.  
  73. //Create image
  74. imagepng($bg);
  75.  
  76. //destroy image
  77. imagedestroy($bg);
  78. } else {
  79. include ("enter_field.php");
  80. }
  81. ?>

enter_field.php
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Img to Png</title>
  6. <style type="text/css">
  7. html{
  8. font-family: Arial, Helvetica, sans-serif;
  9. background-image: url(bg.gif);
  10. color:#FFF;
  11. }
  12. img.header {
  13. border:0px;
  14. }
  15. #enterfield {
  16. position:fixed;
  17. top: 100px;
  18. width: 70%;
  19. left: 15%;
  20. height: 375px;
  21. font-size: 16px;
  22. line-height: 25px;
  23. background-image: url(bg.png);
  24. }
  25. #enterfield.error{
  26. position:fixed;
  27. top: 500px;
  28. width: 70%;
  29. left: 15%;
  30. height: 40px;
  31. background-image: url(bg_red.png);
  32. }
  33. #enterfield.normal{
  34. }
  35. #counter{
  36. position:fixed;
  37. bottom:0;
  38. right:0;
  39. }
  40. #date{
  41. position:fixed;
  42. bottom:0;
  43. left:0;
  44. }
  45. </head>
  46. <fieldset id="enterfield" class="normal"><Legend>Make text into an transparant image</legend>
  47. <form action="index.php" method="get">
  48. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  49. <tr>
  50. <td><b><h3>Basic</h3></b></td>
  51. <td>&nbsp;</td>
  52. </tr>
  53. <tr>
  54. <td>Text :</td>
  55. <td><input name="txt" type="text" /></td>
  56. </tr>
  57. <tr>
  58. <td>Font :</td>
  59. <td><select name="font">
  60. <option value="MASTERPLAN">Masterplan</option>
  61. <option value="SNIPER">Sniper</option>
  62. <option value="Saint-Andrews Queen">Saint-Andrews Queen</option>
  63. <option value="Harabara">Harabara</option>
  64. <option value="Action_of_The_Time_A_L">Action of the time</option>
  65. <option value="bankgothic-regular-db">BankGothic</option>
  66. <option value="evanescent">Evanescent</option>
  67. <option value="Beyond_Wonderland">Beyond wonderland</option>
  68. </select>
  69. </td>
  70. </tr>
  71. <tr>
  72. <td>Text-Size :</td>
  73. <td><input name="size" type="text" maxlength="3" size="4" /> (fill in for custom, default = 50)</td>
  74. </tr>
  75. <tr>
  76. <td>Width :</td>
  77. <td><input name="width" type="text" maxlength="4" size="5" /> (fill in for custom, default = 500)</td>
  78. </tr>
  79. <tr>
  80. <td><h3><b>Color:</b></h3></td>
  81. <td>&nbsp;</td>
  82. </tr>
  83. <tr>
  84. <td valign="top"><b>Select:</b><br />
  85. <select name="color">
  86. <option value="black">Black</option>
  87. <option value="white">White</option>
  88. <option value="red">Red</option>
  89. <option value="green">Green</option>
  90. <option value="yellow">Yellow</option>
  91. <option value="blue">Blue</option>
  92. <option value="grey">Grey</option>
  93. <option value="custom">Custom</option>
  94. </select></td>
  95. <td valign="top"><b>Custom:</b><br />
  96. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  97. <tr>
  98. <td width="75px">
  99. Red :
  100. </td>
  101. <td>
  102. <input name="red" value="0" size="4" maxlength="3" type="text" /><br />
  103. </td>
  104. </tr>
  105. <tr>
  106. <td>
  107. Green :
  108. </td>
  109. <td>
  110. <input name="green" value="0" size="4" maxlength="3" type="text" /><br />
  111. </td>
  112. </tr>
  113. <tr>
  114. <td>
  115. Blue :
  116. </td>
  117. <td>
  118. <input name="blue" value="0" size="4" maxlength="3" type="text" /><br />
  119. </td>
  120. </td>
  121. </tr>
  122. </table>
  123. </td>
  124. </tr>
  125. <input type="submit" value="Convert">
  126. </legend>
  127. </form>
  128. <?php
  129. if (!empty ($_GET['e']))
  130. {
  131. echo '<fieldset id="enterfield" class="error"><legend>Error</legend>';
  132. $error = $_GET['e'];
  133. switch ($error)
  134. {
  135. case 't':
  136. echo "Please fill in a text.";
  137. break;
  138. }
  139. echo "</fieldset>";
  140. }
  141. ?>
  142. </body>
  143. </html>
Download code! Download code (.txt)

 Bekijk een voorbeeld van dit script!
 Stemmen
Niet ingelogd.

 Reacties
Post een reactie
Geen reacties (0)
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.052s